from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-08 14:02:28.185144
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 08, May, 2022
Time: 14:02:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2163
Nobs: 650.000 HQIC: -49.5957
Log likelihood: 7985.96 FPE: 2.27217e-22
AIC: -49.8362 Det(Omega_mle): 1.98046e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325395 0.061389 5.301 0.000
L1.Burgenland 0.105100 0.039106 2.688 0.007
L1.Kärnten -0.110159 0.020504 -5.373 0.000
L1.Niederösterreich 0.195247 0.081608 2.393 0.017
L1.Oberösterreich 0.119817 0.080595 1.487 0.137
L1.Salzburg 0.258280 0.041550 6.216 0.000
L1.Steiermark 0.043604 0.054577 0.799 0.424
L1.Tirol 0.105600 0.044048 2.397 0.017
L1.Vorarlberg -0.063271 0.038917 -1.626 0.104
L1.Wien 0.026190 0.071417 0.367 0.714
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050562 0.131186 0.385 0.700
L1.Burgenland -0.032770 0.083568 -0.392 0.695
L1.Kärnten 0.040283 0.043816 0.919 0.358
L1.Niederösterreich -0.188358 0.174393 -1.080 0.280
L1.Oberösterreich 0.447269 0.172230 2.597 0.009
L1.Salzburg 0.285444 0.088791 3.215 0.001
L1.Steiermark 0.107877 0.116628 0.925 0.355
L1.Tirol 0.313420 0.094129 3.330 0.001
L1.Vorarlberg 0.021951 0.083165 0.264 0.792
L1.Wien -0.037420 0.152616 -0.245 0.806
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190053 0.031503 6.033 0.000
L1.Burgenland 0.090409 0.020068 4.505 0.000
L1.Kärnten -0.007971 0.010522 -0.758 0.449
L1.Niederösterreich 0.248009 0.041879 5.922 0.000
L1.Oberösterreich 0.156499 0.041360 3.784 0.000
L1.Salzburg 0.041378 0.021322 1.941 0.052
L1.Steiermark 0.024665 0.028007 0.881 0.378
L1.Tirol 0.086558 0.022604 3.829 0.000
L1.Vorarlberg 0.055159 0.019971 2.762 0.006
L1.Wien 0.116710 0.036650 3.184 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112480 0.031593 3.560 0.000
L1.Burgenland 0.045582 0.020126 2.265 0.024
L1.Kärnten -0.014223 0.010552 -1.348 0.178
L1.Niederösterreich 0.179911 0.041999 4.284 0.000
L1.Oberösterreich 0.327389 0.041478 7.893 0.000
L1.Salzburg 0.101812 0.021383 4.761 0.000
L1.Steiermark 0.110165 0.028087 3.922 0.000
L1.Tirol 0.097544 0.022669 4.303 0.000
L1.Vorarlberg 0.059613 0.020028 2.976 0.003
L1.Wien -0.021034 0.036754 -0.572 0.567
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115743 0.058845 1.967 0.049
L1.Burgenland -0.043110 0.037485 -1.150 0.250
L1.Kärnten -0.046584 0.019654 -2.370 0.018
L1.Niederösterreich 0.142812 0.078226 1.826 0.068
L1.Oberösterreich 0.159004 0.077256 2.058 0.040
L1.Salzburg 0.283146 0.039828 7.109 0.000
L1.Steiermark 0.054276 0.052315 1.037 0.300
L1.Tirol 0.167243 0.042223 3.961 0.000
L1.Vorarlberg 0.096889 0.037305 2.597 0.009
L1.Wien 0.072814 0.068458 1.064 0.287
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058962 0.046393 1.271 0.204
L1.Burgenland 0.030994 0.029553 1.049 0.294
L1.Kärnten 0.051617 0.015495 3.331 0.001
L1.Niederösterreich 0.204022 0.061672 3.308 0.001
L1.Oberösterreich 0.320693 0.060907 5.265 0.000
L1.Salzburg 0.039939 0.031400 1.272 0.203
L1.Steiermark 0.007101 0.041244 0.172 0.863
L1.Tirol 0.129916 0.033288 3.903 0.000
L1.Vorarlberg 0.065574 0.029410 2.230 0.026
L1.Wien 0.091929 0.053971 1.703 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172658 0.055685 3.101 0.002
L1.Burgenland 0.006036 0.035472 0.170 0.865
L1.Kärnten -0.065230 0.018599 -3.507 0.000
L1.Niederösterreich -0.097154 0.074025 -1.312 0.189
L1.Oberösterreich 0.205460 0.073107 2.810 0.005
L1.Salzburg 0.054708 0.037689 1.452 0.147
L1.Steiermark 0.240071 0.049505 4.849 0.000
L1.Tirol 0.500773 0.039955 12.533 0.000
L1.Vorarlberg 0.060594 0.035301 1.717 0.086
L1.Wien -0.075586 0.064781 -1.167 0.243
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148403 0.061744 2.404 0.016
L1.Burgenland 0.004950 0.039332 0.126 0.900
L1.Kärnten 0.060173 0.020622 2.918 0.004
L1.Niederösterreich 0.182857 0.082079 2.228 0.026
L1.Oberösterreich -0.058741 0.081061 -0.725 0.469
L1.Salzburg 0.206985 0.041790 4.953 0.000
L1.Steiermark 0.132854 0.054892 2.420 0.016
L1.Tirol 0.070298 0.044302 1.587 0.113
L1.Vorarlberg 0.143833 0.039142 3.675 0.000
L1.Wien 0.110252 0.071830 1.535 0.125
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377746 0.036319 10.401 0.000
L1.Burgenland -0.001042 0.023136 -0.045 0.964
L1.Kärnten -0.021888 0.012131 -1.804 0.071
L1.Niederösterreich 0.210744 0.048281 4.365 0.000
L1.Oberösterreich 0.225858 0.047682 4.737 0.000
L1.Salzburg 0.039000 0.024582 1.587 0.113
L1.Steiermark -0.013710 0.032289 -0.425 0.671
L1.Tirol 0.095497 0.026060 3.665 0.000
L1.Vorarlberg 0.053620 0.023024 2.329 0.020
L1.Wien 0.036253 0.042252 0.858 0.391
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036213 0.113005 0.173214 0.141334 0.101923 0.084720 0.038636 0.209964
Kärnten 0.036213 1.000000 -0.021343 0.134198 0.052385 0.089919 0.441405 -0.060783 0.092678
Niederösterreich 0.113005 -0.021343 1.000000 0.322544 0.130136 0.286197 0.076357 0.160788 0.296839
Oberösterreich 0.173214 0.134198 0.322544 1.000000 0.221553 0.309829 0.168943 0.149730 0.249257
Salzburg 0.141334 0.052385 0.130136 0.221553 1.000000 0.131713 0.097058 0.114212 0.130384
Steiermark 0.101923 0.089919 0.286197 0.309829 0.131713 1.000000 0.139678 0.119111 0.050293
Tirol 0.084720 0.441405 0.076357 0.168943 0.097058 0.139678 1.000000 0.069372 0.149669
Vorarlberg 0.038636 -0.060783 0.160788 0.149730 0.114212 0.119111 0.069372 1.000000 0.006593
Wien 0.209964 0.092678 0.296839 0.249257 0.130384 0.050293 0.149669 0.006593 1.000000